package fast.mvc;

import java.awt.Dimension;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.TreeMap;

import javax.swing.AbstractButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JPanel;

import fast.data.CharacterClass;
import fast.data.Spec;

public class SpecPanel extends JPanel {

	private static final long serialVersionUID = -4722933664779306322L;
	private Spec spec;
	private Map<String,JComponent> options = new TreeMap<String,JComponent>();

	public SpecPanel(Spec spec){
		this.spec = spec;
		this.setLayout(null);
		initOptions();
		showOptions();
		this.setVisible(true);
	}
	
	public SpecPanel() {
	}

	private void initOptions(){
		if(Arrays.asList(Spec.getSpecsByCharacterClass(CharacterClass.rogue)).contains(spec)){
			options.put("use_and_get_tott",  new JCheckBox("Use and Get Tricks of the Trade"));
		}
		if(spec == Spec.Combat){
			options.put("combat_use_rupture",  new JCheckBox("Use Rupture"));
			options.put("combat_use_rupture_during_sync",  new JCheckBox("Use Rupture during Sync AR/SB"));
			options.put("sync_ar_with_sb", new JCheckBox("Sync AR with SB"));
			options.put("combat_pool_before_sb", new JCheckBox("Pool before Shadowblades"));
			options.put("combat_waste_cp", new JCheckBox("Waste CP to always make 5 CP finisher (only works without anticipation)"));
			options.put("combat_use_blade_flurry", new JCheckBox("Use Blade Flurry"));
			JComboBox<Integer> bf_targets = new JComboBox<Integer>(new Integer[]{1,2,3,4});
			// TODO get bf_targets working
			options.put("blade_flurry_targets", bf_targets);
		}else if(spec == Spec.Assassination){
			options.put("assa_pool_before_sb", new JCheckBox("Pool before Shadowblades"));
		}
	}
	
	private void showOptions(){
		int i = 0;
		for(JComponent jcheck : options.values()){
			jcheck.setBounds(0, 20*i, 500, 20);
			this.add(jcheck);
			i++;
		}
		this.setPreferredSize(new Dimension(300,1+i*20));
		this.setSize(new Dimension(300,1+i*20));
	}

	public void setOptions(HashSet<String> activeSettings) {
		for(String setting : activeSettings){
			if(options.get(setting) != null)
				((AbstractButton) options.get(setting)).setSelected(true);
		}
	}

	public Map<String, JComponent> getOptions() {
		return options;
	}

}
